package com.damie.component;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//解决跨域问题的配置类，一次配置即可。使用该配置类后不用在控制器上加@CrossOrigin
@CrossOrigin
public class CrosConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")//所有路径
//        .allowedOriginPatterns("*")//授权的源，springboot版本较高时
        .allowedOrigins("GET","POST","PUT","DELETE","HEAD","OPTIONS")//请求方式
        .allowCredentials(true)     //是否开启ajax相关的cookie提交
        .allowedHeaders("*")        //控制那些controller能发送请求
        .maxAge(3600);
    }
}
